﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_CopyDocument]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_CopyDocument];
GO
CREATE PROCEDURE [dbo].[sproc_CopyDocument]
    @DocID int,
    @ToID int
/*

===========================================================
功能:    拷贝文档
参数:
    @DocID int        :    文档ID
    @ToID int        :    拷贝到的组ID

===========================================================

*/
AS
DECLARE @NewDocID int
--复制文档主体
INSERT INTO uds_document (ClassID,DocTitle,DocContent,DocApprover,DocApproveDate,DocApproved,DocLastViewDate,DocLastViewer,DocViewedTimes,DocType,DocAddedBy,DocAddedDate,DocAttribute,DocDeletion,DocSign)
    SELECT @ToID,DocTitle,DocContent,DocApprover,DocApproveDate,DocApproved,DocLastViewDate,DocLastViewer,DocViewedTimes,DocType,DocAddedBy,DocAddedDate,DocAttribute,DocDeletion,@@spid 
        FROM uds_document
        WHERE DocID = @DocID
--复制文档的附件
SET @NewDocID = @@IDENTITY
INSERT INTO uds_files (DocID,[FileName],FileSize,FileAttribute,FileVisualPath,FileAuthor,FileCatlog,FileAddedDate)
    SELECT @NewDocID,[FileName],FileSize,FileAttribute,FileVisualPath,FileAuthor,FileCatlog,getdate() 
        FROM uds_files
        WHERE DocID = @DocID